package practice;


import org.junit.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class JavascriptExecutorTest{
	
	@Test
	public void shouldHandleJavascript(){
		WebDriver driver = new FirefoxDriver();
		driver.manage().window().maximize();
		driver.get("http://www.toolsqa.com/automation-practice-switch-windows/");
		if (driver instanceof JavascriptExecutor) {
			((JavascriptExecutor) driver)
				.executeScript("newAlert()");
		}
		
		Alert alert=driver.switchTo().alert();
		System.out.println(alert.getText());
		alert.accept();
		driver.switchTo().defaultContent();
	}
	
}